package com.example.spark.config;

import io.minio.MinioClient;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 *  读取配置文件的内容赋值给属性
 */

@Data
@Component
@ConfigurationProperties(prefix = "spring.minio")
public class MinioCloudStorageConfig {

    //accessKey类似于用户ID，用于唯一标识你的账户
    private String accessKey;

    //secretKey是你账户的密码
    private String secretKey;

    // Minio 服务端 api地址
    private String url;

    //默认存储桶
    private String bucketName;

    //MinIO上传路径前缀
    private String minioPrefix;

    /**
     * 构建 操作Minio的客户端
     * @return
     */
    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(url)
                .credentials(accessKey, secretKey)
                .build();
    }

}
